/**
 * 表情逻辑组件
 */
var EmojiUtil = {
    /**
     * 表情动画类型
     */
    emojiType: {
        caishen: 'caishen',//财神表情
        xiangxi: 'xiangxi',//湘西表情
        emoji_sp: "emoji_sp",//表情
        emoji: "emoji",//统一表情
        prop_sp: "prop_sp",//道具
        kwx_majiang: "kwx_majiang",
        niuniu: "niuniu",
        pdk: "pdk",
        fsp: 'fsp',
        psz: "psz",
        phz: "phz_face",//跑胡子表情
        phz_hyphz: "phz_hyphz"//跑胡子表情,
    },

    /**
     * 道具配置
     */
    _effectEmojiCfg: {
        1: {'name': 'zan'},
        2: {'name': 'bomb'},
        3: {'name': 'egg'},
        4: {'name': 'shoe'},
        5: {'name': 'flower'},
        6: {'name': 'jiatelin'},

        7: {'name': 'maobi'},
        8: {'name': 'gongjian'},
        9: {'name': 'zhayao'},
        10: {'name': 'dapao'},

        11: {'name': 'che'},
        12: {'name': 'ship'},
        13: {'name': 'plane'},
        14: {'name': 'tiaoxing'},
        15: {'name': 'bingtong'},


        16: {'name': 'daoshui'},
        17: {'name': 'pengbei'},
        18: {'name': 'woshou'},
        19: {'name': 'xianbing'},
        20: {'name': 'zhuaji'},
    },

    effectEmojiCfgSelf: {
        1: {'name': 'expression1'},
        2: {'name': 'expression2'},
        3: {'name': 'expression3'},
        4: {'name': 'expression4'},
        5: {'name': 'expression5'},
        6: {'name': 'expression6'},
        7: {'name': 'expression7'},
        8: {'name': 'expression8'},
        9: {'name': 'expression9'},
    },

    /**
     * 道具间隔时间
     */
    _effectEmojiShengyinTimeCfg: {
        'zhayao': 800,
        'maobi': 0,
        'gongjian': 800,
        'caishen': 0,
        'qifu': 0,
        'dapao': 800,
        'bianpao': 1700,
        'zhuaji': 1000,
        'daoshui': 1000,
        'laolong': 1000,
        'jiaoshui': 1000,
        'liwuzhadan': 1200,
        'bingtong': 800,
        'xihongshi': 1000,
        'tiaoxing': 1200,

    },

    _emojiSpTimeCfg: {
        'woshou': 800,
        'laolong': 800,
        'liwuzhadan': 1200,
        'huaquan': 1200,
        'che': 1200,
        'tiaoxing': 1200,

    },

    _emojiCfgSelfIndexs: {
        expression1: {index: 1, name: 'expression1'},
        expression2: {index: 2, name: 'expression2'},
        expression3: {index: 3, name: 'expression3'},
        expression4: {index: 4, name: 'expression4'},
        expression5: {index: 5, name: 'expression5'},
        expression6: {index: 6, name: 'expression6'},
        expression7: {index: 7, name: 'expression7'},
        expression8: {index: 8, name: 'expression8'},
        expression9: {index: 9, name: 'expression9'},
    },
    _openSelf: chat.collectFeesEmojiTest ? [
        "expression1",
        "expression2",
        "expression3",
        "expression4",
        "expression5",
        "expression6",
        "expression7",
        "expression8",
        "expression9",
    ] : [
        "expression1",
        "expression2",
        "expression3",
        "expression4",
        "expression5",
        "expression6",
        "expression7",
        "expression8",
        "expression9",
    ],


    _emojiCfgOtherIndexs: {
        zan: {index: 1},
        bomb: {index: 2},
        egg: {index: 3},
        shoe: {index: 4},
        //flower: {index: 5},
        //jiatelin: {index: 6},
        //maobi: {index: 7},
        //gongjian: {index: 8},
        zhayao: {index: 9},
        //dapao: {index: 10},
        che: {index: 11},
        ship: {index: 12},
        plane: {index: 13},
        tiaoxing: {index: 14},

        /**
         * 新表情
         */
        bingtong: {
            index: 15,
            isNew: true,
            beginAni: null,
            ingAni: {filepath: 'hd_bingtong01', aniname: 'fly'},
            endAni: {filepath: 'hd_bingtong01', aniname: 'animation', audio: 'hd_bingtong01', toJx: true}
        },

        daoshui: {
            index: 16,
            isNew: true,
            beginAni: null,
            ingAni: {filepath: 'hd_daocha01', aniname: 'fly'},
            endAni: {filepath: 'hd_daocha01', aniname: 'animation', audio: 'hd_daocha01', toJx: true}
        },
        dapao: {
            index: 10,
            isNew: true,
            beginAni: {
                filepath: 'hd_dapao01',
                aniname: 'animation',
                rotation: 90,
                delayTime: 2200,
                audio: 'hd_dapao01'
            },
            ingAni: null,
            endAni: {filepath: 'hd_dapao01_end', aniname: 'animation', audio: 'hd_dapao01_end'}
        },
        pengbei: {
            index: 17,
            isNew: true,
            beginAni: null,
            ingAni: {filepath: 'hd_ganbei01', aniname: 'fly'},
            endAni: {filepath: 'hd_ganbei01', aniname: 'animation', audio: 'hd_ganbei01', toJx: true}
        },
        gongjian: {
            index: 8,
            isNew: true,
            beginAni: {
                filepath: 'hd_gongjian01',
                aniname: 'animation',
                rotation: 0,
                delayTime: 2000,
                audio: 'hd_gongjian01'
            },
            ingAni: null,
            endAni: {filepath: 'hd_gongjian01_end', aniname: 'animation', rotation: 0, audio: 'hd_gongjian01_end'}
        },

        jiatelin: {
            index: 6,
            isNew: true,
            beginAni: {
                filepath: 'hd_jiguanqiang01',
                aniname: 'animation',
                rotation: 90,
                delayTime: 0,
                audio: 'hd_jiguanqiang01'
            },
            ingAni: {filepath: 'hd_jiguanqiang01', aniname: 'fly', extend: true},
            endAni: {filepath: 'hd_jiguanqiang01_end', aniname: 'animation'}
        },
        maobi: {
            index: 7,
            isNew: true,
            beginAni: null,
            ingAni: {filepath: 'hd_maobi01', aniname: 'fly'},
            endAni: {filepath: 'hd_maobi01', aniname: 'animation', audio: 'hd_maobi01'}
        },
        flower: {
            index: 5,
            isNew: true,
            beginAni: null,
            ingAni: {filepath: 'hd_meigui01', aniname: 'fly'},
            endAni: {filepath: 'hd_meigui01', aniname: 'animation', audio: 'hd_meigui01'}
        },
        woshou: {
            index: 18,
            isNew: true,
            beginAni: null,
            ingAni: {filepath: 'hd_woshou01', aniname: 'fly'},
            endAni: {filepath: 'hd_woshou01', aniname: 'animation', audio: 'hd_woshou01'}
        },
        xianbing: {
            index: 19,
            isNew: true,
            beginAni: null,
            ingAni: {filepath: 'hd_xianbing01', aniname: 'fly', audio: 'hd_xianbing01'},
            endAni: {filepath: 'hd_xianbing01', aniname: 'animation'}
        },
        zhuaji: {
            index: 20,
            isNew: true,
            beginAni: null,
            ingAni: {filepath: 'hd_zhuaji01', aniname: 'fly'},
            endAni: {filepath: 'hd_zhuaji01', aniname: 'animation', audio: 'hd_zhuaji01', toJx: true}
        },

    },

    _openOther: chat.collectFeesEmojiTest ? [
        'shoe',
        'egg',
        'flower',
        'woshou',
        'zhuaji',

        'zan',
        'bomb',
    ] : [
        'shoe',
        'egg',
        'flower',
        'woshou',
        'zhuaji',

        'zan',
        'bomb',
    ],
    /**
     * 购买方式
     */
    buyType: "fangka",
    buyTypeDesc: {
        fangka: "张房卡",
        diamonds: "个钻石",
        coin: "个金币"
    },
    /**
     * 道具队列
     */
    _effectEmojiQueue: {},
    /**
     * 初始化表情动画
     */
    initUtil: function (node) {
        var self = this;
        this.room = node;
        //隐藏
        for (var i = 0; i < 12; i++) {
            var ChatInfo = this.room.getChatInfoNode(i, true);
            if (ChatInfo) {
                var prop = ChatInfo.getChildren();
                for (var k = 0; k <= prop.length; k++) {
                    var Child = prop[k];
                    if (Child) {
                        Child.setVisible(false);
                    }
                }
            }
        }
        /**
         * 表情队列
         */
        this._effectEmojiQueue = {};
        /**
         * Go语言聊天
         * @type {Object}
         */
        network.addListener(P.GS_Chat, function (data) {
            var jsData = JSON.parse(data.Msg);
            var uid = data.FromUser;
            var type = jsData.type;
            var content = decodeURIComponent(jsData.content);
            var voice = jsData.voice; //获得文字信息
            if (type == 'biaoqingdonghua') {
                var data = JSON.parse(content);
                data.target_id = data.target_uid;
                network.selfRecv({"code": 4990, "data": data});
            } else {
                self._showChat(self.room.getRowByUid(uid), type, content, voice, uid);
            }
        }, this.room);
        /**
         * Java表情4990
         * @type {Object}
         */
        network.addListener(MsgCode.AddEffectEmoji, function (data) {
            var from_uid = data['from_gid'] || data['from_uid'];
            var target_id = data['target_gid'] || data['target_uid'] || data['target_id'];
            if (self._effectEmojiCfg[data.emoji_idx] == undefined) {
                return;
            }

            if (self.room.getRowByUid && target_id && target_id[0]) {
                if (self.room.getRowByUid(target_id[0]) == self.room.getOriginalPos() && settingData.pingBiBiaoQing) {
                    return;
                }
            }
            if (data.emoji_idx == 3) {
                self._showEgg(from_uid, target_id, data.emoji_idx, data.emoji_times);
            } else if (data.emoji_idx == 4) {
                self._showShoes(from_uid, target_id, data.emoji_idx, data.emoji_times);
            } else {
                self._addEffectEmojiQueue(from_uid, target_id, data.emoji_idx, data.emoji_times);
            }
        }, this.room);


        /**
         * Java聊天3018
         * @type {Object}
         */
        network.addListener(MsgCode.Query_Emoji, function (date) {
            if (date.errorMsg) {
                date.errorMsg = date.errorMsg.replace('\\n', '\n');
                showAlert(date.errorMsg);
                return;
            }
            if (date.cmd == 'queryEmoji') {
                gameData.emoji = date.emoji;//数量
                gameData.price = date.price;//价格
                if (date['ShowEmoji'] && date['ShowEmoji'] != "") {
                    var ShowEmoji = date['ShowEmoji'].split(',');
                    gameData.ShowEmoji = [];
                    for (var i = 0; i < ShowEmoji.length; i++) {
                        if (self._emojiCfgSelfIndexs[ShowEmoji[i]] != undefined) {
                            gameData.ShowEmoji.push(ShowEmoji[i]);
                            // if (gameData.ShowEmoji.length >= 10) {
                            //     break;
                            // }
                        }
                    }
                }
                if (date['ShowItem'] && date['ShowItem'] != "") {
                    var ShowItem = date['ShowItem'].split(',');
                    gameData.ShowItem = [];
                    for (var i = 0; i < ShowItem.length; i++) {
                        if (self._emojiCfgOtherIndexs[ShowItem[i]] != undefined) {
                            gameData.ShowItem.push(ShowItem[i]);
                            // if (gameData.ShowItem.length >= 10) {
                            //     break;
                            // }
                        }
                    }
                }
            } else if (date.cmd == 'buyEmoji') {

            } else if (date.cmd == 'useEmoji') {

            }
        }, this.room);

        /**
         * Java聊天3008
         * @type {Object}
         */
        network.addListener(MsgCode.ShowChat, function (data) {
            var uid = data['gid'] || data['uid'];
            var type = data['type'];
            var voice = data['voice'];
            var content = decodeURIComponent(data['content']);
            self._showChat(self.room.getRowByUid(uid), type, content, voice, uid);
        }, this.room);
        //showOption:   0|0x2|0x4|0x8   0 2 4 8
        network.send(MsgCode.Query_Emoji, {
            cmd: 'queryEmoji',
            uid: gameData.uid,
            room_id: gameData.roomId,
            showOption: 0 | 0x2 | 0x4 | 0x8
        });
    },
    /**
     * 删除网络监听
     */
    _removeJianTing: function () {
        network.removeListener(MsgCode.AddEffectEmoji);
        network.removeListener(MsgCode.Query_Emoji);
        network.removeListener(MsgCode.ShowChat);
        network.removeListener(P.GS_Chat);
    },
    /**
     * 添加表情队列
     */
    _addEffectEmojiQueue: function (caster, patientList, emojiId, times) {
        var self = this;
        if (!cc.sys.isObjectValid(self.room)) return;
        var _casterRow = self.room.getRowByUid(caster);
        var _patientRowList = [];
        for (var _j = 0; _j < patientList.length; _j++) {
            _patientRowList.push(self.room.getRowByUid(patientList[_j]));
        }
        if (_.isUndefined(self._effectEmojiQueue[_casterRow])) {
            self._effectEmojiQueue[_casterRow] = [];
        }
        var _needBigenQueue = self._isEffectEmojiEmpty();
        var _obj = {};
        _obj.patientList = _patientRowList;
        _obj.emojiId = emojiId;
        for (var _i = 0; _i < times; _i++) {
            self._effectEmojiQueue[_casterRow].push(_obj);
        }
        if (_needBigenQueue) {
            self._startEffectEmojiQueue();
        }
    },
    /**
     * 是否有表情队列
     */
    _isEffectEmojiEmpty: function () {
        var self = this;
        if (!cc.sys.isObjectValid(self.room)) return true;
        for (var _key in self._effectEmojiQueue) {
            if (self._effectEmojiQueue.hasOwnProperty(_key)) {
                if (self._effectEmojiQueue[_key].length > 0) {
                    return false;
                }
            }
        }
        return true;
    },
    /**
     * 开始表情队列
     */
    _startEffectEmojiQueue: function () {
        var self = this;
        if (!cc.sys.isObjectValid(self.room)) return;
        for (var _key in self._effectEmojiQueue) {
            if (self._effectEmojiQueue.hasOwnProperty(_key)) {
                var _obj = self._effectEmojiQueue[_key];
                if (_obj.length > 0) {
                    for (var _i = 0; _i < _obj[0].patientList.length; _i++) {
                        self._playEffectEmoji(_key, _obj[0].patientList[_i], _obj[0].emojiId);
                    }
                    self._effectEmojiQueue[_key].splice(0, 1);
                }
            }
        }
        if (!self._isEffectEmojiEmpty()) {
            self.room.runAction(cc.sequence(
                cc.delayTime(0.3),
                cc.callFunc(function () {
                    self._startEffectEmojiQueue();
                })
            ))
        }
    },
    /**
     * 播放表情动画
     */
    _playEffectEmoji: function (caster, patient, emojiId) {
        var self = this;
        if (!cc.sys.isObjectValid(self.room)) return;
        var _emojiCfg = self._effectEmojiCfg[emojiId];
        if (_.isUndefined(_emojiCfg)) {
            return;
        }
        var sp = new cc.Sprite();
        self.room.addChild(sp, 30);
        var cfg = self._emojiCfgOtherIndexs[_emojiCfg.name];
        if(cfg && cfg.isNew){
            self._effectEmojiSpBeginByQiji(_emojiCfg, sp, caster, patient);
        } else if (chat.res["sp_" + _emojiCfg.name + "_json"]) {
            self._effectEmojiSpBegin(_emojiCfg, sp, caster, patient, true);
        } else {
            self._effectEmojiBegin(_emojiCfg, sp, caster, patient);
        }
    },
    /**
     * 播放表情动画开始
     */
    _effectEmojiBegin: function (emojiCfg, sp, caster, patient) {
        var self = this;
        if (!cc.sys.isObjectValid(self.room)) return;
        var pos = self.room.getEffectEmojiPos(caster, patient, true);
        var _beginPos = pos[caster];
        sp.setPosition(_beginPos);
        var effect_emoji = 'effect_emoji_' + emojiCfg.name + "_1";

        playAnimScene(sp, chat.res[effect_emoji], 0, 0, false, function () {
            sp.removeAllChildren();
            self._effectEmojiflying(emojiCfg, sp, caster, patient);
        });
    },
    /**
     * 播放表情动画进行中
     */
    _effectEmojiflying: function (emojiCfg, sp, caster, patient) {
        var self = this;
        if (!cc.sys.isObjectValid(self.room)) return;
        var pos = self.room.getEffectEmojiPos(caster, patient, true);
        var maxScale = 1;
        var _endPos = pos[patient];
        sp.stopAllActions();
        var effect_emoji = 'effect_emoji_' + emojiCfg.name + "_2";
        playAnimScene(sp, chat.res[effect_emoji], 0, 0, true);
        sp.runAction(cc.sequence(
            patient != self.room.getOriginalPos() ? cc.moveTo(0.5, _endPos) : cc.spawn(cc.moveTo(0.5, _endPos), cc.scaleTo(0.5, maxScale)),
            cc.callFunc(function () {
                sp.removeAllChildren();
                self._effectEmojiend(emojiCfg, sp, caster, patient);
            })
        ));
    },
    _effectEmojiSpEndByQij: function (emojiCfg, sp, caster, patient, isnotmid) {
        var self = this;
        if (!cc.sys.isObjectValid(self.room)) return;

        isnotmid = true;
        var pos = self.room.getEffectEmojiPos(caster, patient, isnotmid);
        var _beginPos = pos[caster];
        var _endPos = pos[patient];
        var cfg = self._emojiCfgOtherIndexs[emojiCfg.name];
        var spFile = chat.res["sp_" + cfg.endAni.filepath + "_json"];
        if (!spFile) {
            return;
        }
        var emoji = playSpine(spFile, cfg.endAni.aniname, false, function () {
            setTimeout(function () {
                emoji.removeFromParent(true);
                sp.removeFromParent(true);
            }, 10)
        });
        if (cfg.endAni.audio) {
            playEffect(cfg.endAni.audio + '_mp3');
        }
        emoji.setPosition(_endPos);
        if (!cc.isUndefined(cfg.endAni.rotation)) {
            emoji.setRotation(cfg.endAni.rotation - 180 * Math.atan2(_endPos.y - _beginPos.y, _endPos.x - _beginPos.x) / Math.PI)
        }
        if (cfg.endAni.toJx && _endPos.x < cc.winSize.width / 2) {
            emoji.setScaleX(-1);
        }
        self.room.addChild(emoji);
    },
    _effectEmojiSpflyingByQij: function (emojiCfg, sp, caster, patient, isnotmid) {
        var self = this;
        if (!cc.sys.isObjectValid(self.room)) return;

        isnotmid = true;
        var maxScale = 1;
        var pos = self.room.getEffectEmojiPos(caster, patient, isnotmid);
        var _beginPos = pos[caster];
        var _endPos = pos[patient];
        var cfg = self._emojiCfgOtherIndexs[emojiCfg.name];
        var spFile = chat.res["sp_" + cfg.ingAni.filepath + "_json"];
        if (!spFile) {
            return;
        }
        var emoji = playSpine(spFile, cfg.ingAni.aniname, false);
        if (cfg.ingAni.audio) {
            playEffect(cfg.ingAni.audio + '_mp3');
        }
        emoji.setPosition(_beginPos);
        emoji.setLocalZOrder(100);
        self.room.addChild(emoji);
        emoji.runAction(cc.sequence(cc.delayTime(0.7),
            patient != self.room.getOriginalPos() ? cc.moveTo(0.3, _endPos) : cc.spawn(cc.moveTo(0.3, _endPos), cc.scaleTo(0.3, maxScale)),
            cc.callFunc(function () {
                emoji.removeFromParent(true);
                self._effectEmojiSpEndByQij(emojiCfg, sp, caster, patient);
            })));

        /**
         * 机关枪扩展
         */
        if (cfg.ingAni.extend) {
            var getAngleByPos = function (p1, p2) {
                var p = {}
                p.x = p2.x - p1.x;
                p.y = p2.y - p1.y;
                var r = Math.atan2(p.y, p.x) * 180 / Math.PI;
                return r
            };
            var hudu = cc.pAngle(_beginPos, _endPos);
            var angle = cc.radiansToDegrees(hudu);
            angle = 90 - getAngleByPos(_beginPos, _endPos);
            sp.setPosition(_beginPos);
            for (var i = 0; i < 28; i++) {
                setTimeout(function () {
                    var zidan = new cc.Sprite(chat.res.zidan_png);
                    var zidanPos = cc.p(25, 25);
                    zidan.setPosition(zidanPos);
                    zidan.setRotation(angle);
                    zidan.setOpacity(0);
                    sp.addChild(zidan, 30);

                    var x2 = (25 - Math.ceil(Math.random() * 50));
                    var y2 = (25 - Math.ceil(Math.random() * 50));
                    var ePos = cc.p(_endPos.x - _beginPos.x + x2, _endPos.y - _beginPos.y + y2);
                    var lenth = cc.pDistance(zidanPos, ePos);
                    var time = lenth / 3000;
                    zidan.runAction(cc.sequence(
                        cc.spawn(cc.fadeTo(time / 6, 255), cc.moveTo(time, ePos.x, ePos.y))
                        , cc.callFunc(function () {
                            zidan.removeFromParent(true);
                            var dankong = new cc.Sprite(chat.res.dankong_png);
                            dankong.setPosition(cc.p(ePos.x + x2, ePos.y + y2));
                            sp.addChild(dankong, 30);
                        })
                    ));
                }, i * 100 + 800);
            }
        }
    },
    _effectEmojiSpBeginByQiji: function (emojiCfg, sp, caster, patient, isnotmid) {
        var self = this;
        if (!cc.sys.isObjectValid(self.room)) return;
        var cfg = self._emojiCfgOtherIndexs[emojiCfg.name];
        if (!cfg) {
            return;
        }
        if (!cfg.beginAni) {
            self._effectEmojiSpflyingByQij(emojiCfg, sp, caster, patient, isnotmid);
            return
        }
        isnotmid = true;
        var maxScale = 1;
        var pos = self.room.getEffectEmojiPos(caster, patient, isnotmid);
        var _beginPos = pos[caster];
        var _endPos = pos[patient];
        var spFile = chat.res["sp_" + cfg.beginAni.filepath + "_json"];
        if (!spFile) {
            return;
        }
        var emoji = playSpine(spFile, cfg.beginAni.aniname, false, function () {
            setTimeout(function () {
                emoji.removeFromParent(true)
            }, 10)
        });
        if (cfg.beginAni.audio) {
            playEffect(cfg.beginAni.audio + '_mp3');
        }
        emoji.setPosition(_beginPos);
        emoji.setLocalZOrder(100);
        if (!cc.isUndefined(cfg.beginAni.rotation)) {
            emoji.setRotation(cfg.beginAni.rotation - 180 * Math.atan2(_endPos.y - _beginPos.y, _endPos.x - _beginPos.x) / Math.PI)
        }
        self.room.addChild(emoji);
        var delayTime = cfg.beginAni.delayTime || 0;
        if (cfg.ingAni) {
            setTimeout(function () {
                self._effectEmojiSpflyingByQij(emojiCfg, sp, caster, patient);
            }, delayTime);
        } else if (cfg.endAni) {
            setTimeout(function () {
                self._effectEmojiSpEndByQij(emojiCfg, sp, caster, patient);
            }, delayTime);
        }
    },
    /**
     * 播放表情Sp动画开始
     */
    _effectEmojiSpBegin: function (emojiCfg, sp, caster, patient, isnotmid) {
        var self = this;
        if (!cc.sys.isObjectValid(self.room)) return;

        isnotmid = true;
        var maxScale = 1;
        var pos = self.room.getEffectEmojiPos(caster, patient, isnotmid);
        var _beginPos = pos[caster];
        var _endPos = pos[patient];

        var spFile = chat.res["sp_" + emojiCfg.name + "_json"];
        if (spFile == undefined) {
            return;
        }
        var emoji = playSpine(spFile, emojiCfg.name + '1', false, function () {
            if (emojiCfg.name == 'bingtong' || emojiCfg.name == 'maobi' || emojiCfg.name == 'shuai' || emojiCfg.name == 'bianpao' || emojiCfg.name == 'hongbao' || emojiCfg.name == 'zhuaji' || emojiCfg.name == 'daoshui' || emojiCfg.name == 'jiaoshui' || emojiCfg.name == 'xihongshi') {

            } else {
                setTimeout(function () {
                    emoji.removeFromParent(true)
                }, 10)
            }
        });

        var time = self._effectEmojiShengyinTimeCfg[emojiCfg.name];
        setTimeout(function () {
            playEffect('v' + emojiCfg.name);
        }, time);
        emoji.setPosition(_beginPos);
        emoji.setLocalZOrder(100);
        if (emojiCfg.name == 'dapao' || emojiCfg.name == 'gongjian') {
            emoji.setRotation(90 - 180 * Math.atan2(_endPos.y - _beginPos.y, _endPos.x - _beginPos.x) / Math.PI)
        }
        self.room.addChild(emoji)
        if (emojiCfg.name == 'dapao') {
            var paodan = new cc.Sprite(chat.res.sp_baodan_image);
            paodan.setOpacity(0);
            paodan.setPosition(_beginPos);
            self.room.addChild(paodan)
            paodan.runAction(cc.sequence(cc.delayTime(0.7), cc.fadeIn(0),
                patient != self.room.getOriginalPos() ? cc.moveTo(1, _endPos) : cc.spawn(cc.moveTo(1, _endPos), cc.scaleTo(1, maxScale)),
                cc.callFunc(function () {
                    self._effectEmojiend(emojiCfg, sp, caster, patient);
                    paodan.removeFromParent(true);
                })))
        }
        else {
            if (emojiCfg.name == 'bingtong' || emojiCfg.name == 'maobi' || emojiCfg.name == 'xihongshi' || emojiCfg.name == 'shuai' || emojiCfg.name == 'bianpao' || emojiCfg.name == 'hongbao' || emojiCfg.name == 'zhuaji' || emojiCfg.name == 'daoshui' || emojiCfg.name == 'jiaoshui') {
                if (emojiCfg.name == 'hongbao' || emojiCfg.name == 'zhuaji' || emojiCfg.name == 'daoshui') {
                    if (_endPos.x >= cc.winSize.width / 2) {
                        emoji.setScaleX(-1);
                        if (emojiCfg.name == 'hongbao') {//红包动画位置有偏移  前后动画会瞬移  加这个减小视觉冲击效果
                            _endPos.x -= 65;
                        }
                    } else {
                        if (emojiCfg.name == 'hongbao') {
                            _endPos.x += 65;
                        }
                    }
                }
                emoji.runAction(cc.sequence(cc.delayTime(0.7),
                    patient != self.room.getOriginalPos() ? cc.moveTo(0.3, _endPos) : cc.spawn(cc.moveTo(0.3, _endPos), cc.scaleTo(0.3, maxScale)),
                    cc.callFunc(function () {
                        emoji.removeFromParent(true)
                        self._effectEmojiend(emojiCfg, sp, caster, patient);
                    })))
            }
            else {
                var sptime = this._emojiSpTimeCfg[emojiCfg.name];
                if (sptime) {
                    setTimeout(function () {
                        self._effectEmojiend(emojiCfg, sp, caster, patient);
                    }, sptime);
                } else {
                    self._effectEmojiend(emojiCfg, sp, caster, patient, isnotmid);
                }

            }
        }
    },
    /**
     * 播放表情动画结束
     */
    _effectEmojiend: function (emojiCfg, sp, caster, patient, isnotmid) {
        var self = this;
        if (!cc.sys.isObjectValid(self.room)) return;
        isnotmid = true;
        var maxScale = 1;
        var pos = self.room.getEffectEmojiPos(caster, patient, isnotmid);
        var _beginPos = pos[caster];
        var _endPos = pos[patient];

        if (chat.res["sp_" + emojiCfg.name + "_json"]) {
            var spFile = chat.res["sp_" + emojiCfg.name + "_json"];
            if (spFile == undefined) {
                return;
            }
            var emoji = playSpine(spFile, emojiCfg.name + '2', false, function () {
                setTimeout(function () {
                    emoji.removeFromParent(true)
                }, 10)
            });

            if (emojiCfg.name == 'plane') {
                var emoji1 = playSpine(spFile, emojiCfg.name + '3', false, function () {
                    setTimeout(function () {
                        emoji1.removeFromParent(true)
                    }, 10)
                })
                emoji1.setPosition(cc.p(cc.winSize.width / 2, cc.winSize.height / 2));
                emoji1.setScale(1);
                self.room.addChild(emoji1)
            }
            emoji.setScale(1);

            if (emojiCfg.name == 'gongjian') {
                emoji.setRotation(90 - 180 * Math.atan2(_endPos.y - _beginPos.y, _endPos.x - _beginPos.x) / Math.PI)
            } else if (emojiCfg.name == 'hongbao' || emojiCfg.name == 'daoshui' || emojiCfg.name == 'jiaoshui') {
                if (_endPos.x >= cc.winSize.width / 2) {
                    emoji.setScaleX(-1);
                }
            } else if (emojiCfg.name == 'bingtong') {
                if (_endPos.x < cc.winSize.width / 2) {
                    emoji.setScaleX(-1);
                }
            }
            emoji.setPosition(_endPos);

            emoji.setScale(patient != self.room.getOriginalPos() ? 1 : maxScale);
            self.room.addChild(emoji)
        } else {
            playEffect('v' + emojiCfg.name);
            var effect_emoji = 'effect_emoji_' + emojiCfg.name + "_3";
            playAnimScene(sp, chat.res[effect_emoji], 0, 0, false, function () {
                sp.runAction(cc.sequence(
                    cc.fadeOut(0.3),
                    cc.callFunc(function () {
                        sp.removeFromParent();
                    })
                ))
            });
        }
    },


    _showPengbei: function (caster, patientList, emojiId, times) {
        var self = this;
        if (!cc.sys.isObjectValid(self.room)) return;
        if (emojiId == 11 && chat.res['sp_pengbei_json']) {

            var _casterRow = self.room.getRowByUid(caster);
            var _patientRow = self.room.getRowByUid(patientList[0]);
            var pos = self.room.getEffectEmojiPos(_casterRow, _patientRow, true);
            var _beginPos = pos[_casterRow];
            var _endPos = pos[_patientRow];

            var centerPs = cc.p((_beginPos.x + _endPos.x) / 2, (_beginPos.y + _endPos.y) / 2);

            var sp = new cc.Sprite(res.sp_pengbeiBG_png);
            self.room.addChild(sp, 30);
            sp.setPosition(_beginPos);

            var sp1 = new cc.Sprite(res.sp_pengbeiBG_png);
            self.room.addChild(sp1, 30);
            sp1.setPosition(_endPos);

            var time = 0.4;

            sp.runAction(cc.sequence(cc.moveTo(time, centerPs), cc.callFunc(function () {
                sp.removeFromParent(true);
            })));
            var name = this._effectEmojiCfg[emojiId].name;
            var spFile = chat.res["sp_" + name + "_json"];
            if (spFile == undefined) {
                return;
            }


            sp1.runAction(cc.sequence(cc.moveTo(time, centerPs), cc.callFunc(function () {
                playEffect('v' + name);

                var emoji3 = playSpine(spFile, name + 1, false, function () {
                    setTimeout(function () {
                        emoji3.removeFromParent(true);
                    }, 10)
                });
                emoji3.setPosition(centerPs);
                self.room.addChild(emoji3);
                sp1.removeFromParent(true);
            })));
        }
    },

    _showLiMao: function (caster, patientList, emojiId, times) {
        var self = this;
        if (!cc.sys.isObjectValid(self.room)) return;
        if (emojiId == 7 && chat.res['sp_limao_json']) {
            var sp = new cc.Sprite();
            self.room.addChild(sp, 30);
            var _casterRow = self.room.getRowByUid(caster);
            var _patientRow = self.room.getRowByUid(patientList[0]);
            var pos = self.room.getEffectEmojiPos(_casterRow, _patientRow, true);
            var _beginPos = pos[_casterRow];
            sp.setPosition(_beginPos);
            var _endPos = pos[_patientRow];
            var name = this._effectEmojiCfg[emojiId].name;

            var spFile = chat.res["sp_" + name + "_json"];
            if (spFile == undefined) {
                return;
            }

            var emoji = playSpine(spFile, name + 1, false, function () {
                setTimeout(function () {
                    emoji.removeFromParent(true);
                }, 10)
                playEffect('v' + name);
                var emoji2 = playSpine(spFile, name + 2, false, function () {
                    setTimeout(function () {
                        emoji2.removeFromParent(true);
                        sp.setPosition(_endPos);

                        var emoji3 = playSpine(spFile, name + 3, false, function () {
                            setTimeout(function () {
                                emoji3.removeFromParent(true);
                            }, 10)
                        });
                        if (_endPos.x < cc.winSize.width / 2) {
                            emoji3.setScaleX(-1);
                        }
                        sp.addChild(emoji3);

                    }, 10)
                });
                if (_beginPos.x > cc.winSize.width / 2) {
                    emoji2.setScaleX(-1);
                }
                sp.addChild(emoji2);
            });
            if (_beginPos.x > cc.winSize.width / 2) {
                emoji.setScaleX(-1);
            }
            sp.addChild(emoji);

        }
    },

    _playAnimSceneNoCache: function (distNode, res, posx, posy, loop, func) {
        var cacheNode = null;
        if (!cacheNode) {
            var name = res.split("-");
            var animScene = ccs.load(name[0], getCCSFileNamePath(name[0]));
            cacheNode = animScene.node;
            cacheNode.setName(res);
            distNode.addChild(cacheNode);
            cacheNode.runAction(animScene.action);
            cacheNode.setPosition(posx, posy);

            var userdata = cacheNode.getUserData() || {};
            userdata.action = animScene.action;
            cacheNode.setUserData(userdata);
        }

        var userdata = cacheNode.getUserData();
        userdata.action.play('action', loop);
        if (func) {
            userdata.action.setLastFrameCallFunc(function () {
                setTimeout(function () {
                    func();
                }, 10);
            });
        }
        return cacheNode;
    },

    _showShoes: function (caster, patientList, emojiId, times) {
        var self = this;
        if (!cc.sys.isObjectValid(self.room)) return;
        if (emojiId == 4 && chat.res['effect_emoji_shoe_2']) {
            var sp = new cc.Sprite();
            self.room.addChild(sp, 30);
            var _casterRow = self.room.getRowByUid(caster);
            var _patientRow = self.room.getRowByUid(patientList[0]);
            var pos = self.room.getEffectEmojiPos(_casterRow, _patientRow, true);
            var _beginPos = pos[_casterRow];
            var _endPos = pos[_patientRow];
            var hudu = cc.pAngle(_beginPos, _endPos);
            var angle = cc.radiansToDegrees(hudu);
            sp.setPosition(_beginPos);
            var effect_emoji = "effect_emoji_shoe_2";
            var effect_emoji3 = "effect_emoji_shoe_3";

            for (var i = 0; i < 15; i++) {
                setTimeout(function (key) {
                    playEffect("vshoe");

                    var zidan = this._playAnimSceneNoCache(sp, chat.res[effect_emoji] + "-" + key, 0, 0, false, function () {
                        // sp.removeAllChildren();
                    });
                    var zidanPos = cc.p(25, 25);
                    zidan.setPosition(zidanPos);
                    zidan.setRotation(angle);

                    var x2 = (25 - Math.ceil(Math.random() * 80)) * (_patientRow != self.room.getOriginalPos() ? 1 : 1);
                    var y2 = (25 - Math.ceil(Math.random() * 80)) * (_patientRow != self.room.getOriginalPos() ? 1 : 1);
                    var ePos = cc.p(_endPos.x - _beginPos.x + x2, _endPos.y - _beginPos.y + y2);
                    var lenth = cc.pDistance(zidanPos, ePos);
                    var time = lenth / 3000
                    var spa = cc.spawn(cc.fadeTo(time / 6, 255), cc.moveTo(time, ePos.x, ePos.y));
                    zidan.runAction(cc.sequence(
                        _patientRow != self.room.getOriginalPos() ? spa : cc.spawn(spa, cc.scaleTo(time, 1))
                        , cc.callFunc(function (key1) {
                            zidan.removeFromParent(true);
                            var dankong = this._playAnimSceneNoCache(sp, chat.res[effect_emoji3], 0, 0, false, function (key2) {
                                dankong.removeFromParent();
                                if (key2 == 14) {
                                    sp.removeFromParent();
                                }
                            }.bind(this, key1));
                            dankong.setPosition(cc.p(ePos.x + x2, ePos.y + y2));
                            var rotation = Math.random() * 360;
                            dankong.setRotation(rotation);
                            dankong.setScale(1);

                        }.bind(this, key))
                    ));
                }.bind(this, i), i * 100);
            }
        }
    },

    _showEgg: function (caster, patientList, emojiId, times) {
        var self = this;
        if (!cc.sys.isObjectValid(self.room)) return;
        if (emojiId == 3 && chat.res['effect_emoji_egg_2']) {
            var sp = new cc.Sprite();
            self.room.addChild(sp, 30);
            var _casterRow = self.room.getRowByUid(caster);
            var _patientRow = self.room.getRowByUid(patientList[0]);
            var pos = self.room.getEffectEmojiPos(_casterRow, _patientRow, true);
            var _beginPos = pos[_casterRow];
            var _endPos = pos[_patientRow];
            var hudu = cc.pAngle(_beginPos, _endPos);
            var angle = cc.radiansToDegrees(hudu);
            sp.setPosition(_beginPos);
            var effect_emoji = "effect_emoji_egg_2";
            var effect_emoji3 = "effect_emoji_egg_3";

            for (var i = 0; i < 15; i++) {
                setTimeout(function (key) {
                    playEffect("vegg");
                    var zidan = this._playAnimSceneNoCache(sp, chat.res[effect_emoji] + "-" + key, 0, 0);
                    var zidanPos = cc.p(25, 25);
                    zidan.setPosition(zidanPos);
                    zidan.setRotation(angle);

                    var x2 = (25 - Math.ceil(Math.random() * 100)) * (_patientRow != self.room.getOriginalPos() ? 1 : 1);
                    var y2 = (25 - Math.ceil(Math.random() * 100)) * (_patientRow != self.room.getOriginalPos() ? 1 : 1);
                    var ePos = cc.p(_endPos.x - _beginPos.x + x2, _endPos.y - _beginPos.y + y2);
                    var lenth = cc.pDistance(zidanPos, ePos);
                    var time = lenth / 3000
                    var spa = cc.spawn(cc.fadeTo(time / 6, 255), cc.moveTo(time, ePos.x, ePos.y));
                    zidan.runAction(cc.sequence(
                        _patientRow != self.room.getOriginalPos() ? spa : cc.spawn(spa, cc.scaleTo(time, 1))
                        , cc.callFunc(function (key1) {
                            zidan.removeFromParent(true);
                            var dankong = this._playAnimSceneNoCache(sp, chat.res[effect_emoji3], 0, 0, false, function (key2) {
                                dankong.removeFromParent();
                                if (key2 == 14) {
                                    sp.removeFromParent();
                                }
                            }.bind(this, key1));
                            dankong.setPosition(cc.p(ePos.x + x2, ePos.y + y2));
                            var rotation = Math.random() * 360;
                            dankong.setRotation(rotation);
                            dankong.setScale(1);
                        }.bind(this, key))
                    ));
                }.bind(this, i), i * 100);
            }
        }
    },

    /**
     * 播放表情动画加特林
     */
    _showJiaTeLin: function (caster, patientList, emojiId, times) {
        var self = this;
        if (!cc.sys.isObjectValid(self.room)) return;
        if (emojiId == 6 && chat.res.jiatelin_qiang_json) {
            var getAngleByPos = function (p1, p2) {
                var p = {}
                p.x = p2.x - p1.x;
                p.y = p2.y - p1.y;
                var r = Math.atan2(p.y, p.x) * 180 / Math.PI;
                return r
            };
            var sp = new cc.Sprite();
            self.room.addChild(sp, 30);
            var _casterRow = self.room.getRowByUid(caster);
            var _patientRow = self.room.getRowByUid(patientList[0]);
            var pos = self.room.getEffectEmojiPos(_casterRow, _patientRow, true);
            var _beginPos = pos[_casterRow];
            var _endPos = pos[_patientRow];
            var hudu = cc.pAngle(_beginPos, _endPos);
            var angle = cc.radiansToDegrees(hudu);
            angle = 90 - getAngleByPos(_beginPos, _endPos);
            var jiaodu = getAngleByPos(_beginPos, _endPos);
            sp.setPosition(_beginPos);
            var effect_emoji = "jiatelin_qiang_json";
            playEffect("vJiatelin");

            var maxScale = 4;
            for (var i = 0; i < 20; i++) {
                setTimeout(function () {
                    var zidan = new cc.Sprite(chat.res.jiatelin_bullet);
                    var zidanPos = cc.p(25, 25);
                    zidan.setPosition(zidanPos);
                    zidan.setRotation(angle);
                    zidan.setOpacity(0);
                    sp.addChild(zidan, 30);

                    maxScale = 1;
                    pos = self.room.getEffectEmojiPos(_casterRow, _patientRow, true);
                    _beginPos = pos[_casterRow];
                    _endPos = pos[_patientRow];

                    var x2 = (25 - Math.ceil(Math.random() * 50)) * (_patientRow != self.room.getOriginalPos() ? 1 : maxScale);
                    var y2 = (25 - Math.ceil(Math.random() * 50)) * (_patientRow != self.room.getOriginalPos() ? 1 : maxScale);
                    var ePos = cc.p(_endPos.x - _beginPos.x + x2, _endPos.y - _beginPos.y + y2);
                    var lenth = cc.pDistance(zidanPos, ePos);
                    var time = lenth / 3000
                    var spa = cc.spawn(cc.fadeTo(time / 6, 255), cc.moveTo(time, ePos.x, ePos.y));
                    zidan.runAction(cc.sequence(
                        _patientRow != self.room.getOriginalPos() ? spa : cc.spawn(spa, cc.scaleTo(time, maxScale))
                        , cc.callFunc(function () {
                            zidan.removeFromParent(true);
                            var dankong = new cc.Sprite(chat.res.jiatelin_Dankong);
                            dankong.setPosition(cc.p(ePos.x + x2, ePos.y + y2));
                            dankong.setScale(_patientRow != self.room.getOriginalPos() ? 1 : maxScale);
                            sp.addChild(dankong, 30);
                        })
                    ));
                }, i * 100);
            }
            var cacheNode = playAnimScene(sp, chat.res[effect_emoji], 0, 0, false, function () {
                sp.removeAllChildren();
            });
            cacheNode.setRotation(angle);
        }
    },
    /**
     * 对话框隐藏
     */
    _qpAction: function (innerNodes, scale9sprite, duration) {
        scale9sprite.stopAllActions();
        scale9sprite.setVisible(true);
        scale9sprite.setOpacity(255);
        scale9sprite.setScale(1.6, 1.6);
        scale9sprite.runAction(cc.sequence(cc.delayTime(duration), cc.fadeOut(0.5), cc.callFunc(function () {
            for (var i = 0; i < innerNodes.length; i++)
                innerNodes[i].setVisible(false);
        })));
    },
    /**
     * 对话框全部隐藏
     */
    _qpAction2: function (innerNodes, scale9sprite, duration) {
        setTimeout(function () {
            for (var i = 0; i < innerNodes.length; i++)
                innerNodes[i].setVisible(false);
        }, 3000);

    },


    /**
     * 播放语音
     */
    playUrlVoice: function (row, type, content, voice) {
        var self = this;
        var url = decodeURIComponent(content);
        var arr = null;
        if (url.indexOf('.aac') >= 0) {
            arr = url.split(/\.aac/)[0].split(/-/);
        } else if (url.indexOf('.spx') >= 0) {
            arr = url.split(/\.spx/)[0].split(/-/);
        }
        var duration = arr[arr.length - 1] / 1000;
        window.soundQueue = window.soundQueue || [];
        window.soundQueue.push({url: url, duration: duration, row: row});
        if (window.soundQueue.length > 1) {
        } else {
            self.playVoiceQueue();
        }
    },
    /**
     * 播放语音队列
     */
    playVoiceQueue: function () {
        var self = this;
        var queue = window.soundQueue[0];
        if (queue && queue.url && queue.duration && _.isNumber(queue.row)) {
            if (queue.url.indexOf('.aac') >= 0) {
                VoiceUtil.play(queue.url);
            }
            var row = queue.row;
            var duration = queue.duration;
            var innerNodes = [];
            var ChatInfo = self.room.getChatInfoNode(row);
            if (!ChatInfo) {
                return;
            }
            for (var i = (cc.sys.isNative ? 0 : 1); i < ChatInfo.getChildren().length; i++) {
                ChatInfo.getChildren()[i].setVisible(false);
            }
            var yuyin = ChatInfo.getChildByName("yuyin");
            yuyin.setVisible(true);

            var speakerNode = yuyin.getChildByName("pos");
            var resPath = chat.res.ChatSpeaker_json;
            if (!speakerNode.getChildByName(resPath)) {
                speakerNode.removeAllChildren();
                var speakerAnim = playAnimScene(speakerNode, resPath, 0, 0, true);
            }
            innerNodes.push(yuyin);
            ChatInfo.stopAllActions();
            ChatInfo.setVisible(true);
            ChatInfo.setOpacity(255);

            ChatInfo.runAction(cc.sequence(cc.delayTime(duration), cc.fadeOut(0.5), cc.callFunc(function () {
                for (var i = 0; i < innerNodes.length; i++)
                    innerNodes[i].setVisible(false);
            })));

            setTimeout(function () {
                window.soundQueue.shift();
                self.playVoiceQueue();
            }, queue.duration * 1000);
        }
    },
    /**
     * 显示聊天
     */
    _showChat: function (row, type, content, voice, uid) {
        var self = this;
        if (type == 'voice') {
            var url = decodeURIComponent(content);
            if (url && url.split(/\.spx/).length > 2)
                return;
        }
        if (type == 'voice') {
            this.playUrlVoice(row, type, content, voice);
            return;
        }
        var ChatInfo = self.room.getChatInfoNode(row);
        if (!ChatInfo) {
            return;
        }
        for (var i = (cc.sys.isNative ? 0 : 1); i < ChatInfo.getChildren().length; i++)
            ChatInfo.getChildren()[i].setVisible(false);
        var innerNodes = [];
        var duration = 4;

        if (type == EmojiUtil.emojiType.caishen) {
            duration = 2.2;
            var emojiNode = ChatInfo.getChildByName("emoji");
            emojiNode.setVisible(true);
            emojiNode.removeAllChildren();
            var tab = [
                chat.res.sp_lt_cs01_baobao01_json,
                chat.res.sp_lt_cs01_bukaixin01_json,
                chat.res.sp_lt_cs01_caishendao01_json,
                chat.res.sp_lt_cs01_fahongbao01_json,
                chat.res.sp_lt_cs01_fahuo01_json,
                chat.res.sp_lt_cs01_gongxifacai01_json,
                chat.res.sp_lt_cs01_gongxifacai02_json,
                chat.res.sp_lt_cs01_kanxi01_json,
                chat.res.sp_lt_cs01_nizou01_json,
                chat.res.sp_lt_cs01_qiekenao01_json,
                chat.res.sp_lt_cs01_youqianrenxing01_json,
                chat.res.sp_lt_cs01_yun01_json,
            ];
            var emoji = playSpine(tab[content - 1], 'animation', false);
            // emoji.setScale(0.5);
            emoji.setPosition(cc.p(0, -30));
            emojiNode.addChild(emoji);
            innerNodes.push(emojiNode);
        } else if (type == EmojiUtil.emojiType.emoji) {
            duration = 2.2;
            var emojiNode = ChatInfo.getChildByName("emoji");
            emojiNode.setVisible(true);
            emojiNode.removeAllChildren();
            if (content.indexOf("sp_") == 0) {
                duration = 5;
                var emoji = null;
                var name = content.split("_");
                name.splice(0, 1);
                name = name.join('_');
                var spFile = chat.res["sp_" + name + "_json"];
                if (spFile == undefined) {
                    return;
                }
                if(name.indexOf('qf_')>=0){
                    emoji = playSpine(spFile, 'animation', false, function () {
                        setTimeout(function () {
                            emoji.removeFromParent(true);
                        }, 10)
                    });
                    playEffect(name + '_mp3');
                }else if (name == "tuxue" || name == "chuizhuozi") {
                    var time = 0;
                    if (name == "chuizhuozi") {
                        time = 2000;
                    }
                    setTimeout(function () {
                        playEffect('v' + name);
                    }, time)
                    emoji = playSpine(spFile, name + 1, false, function () {
                        setTimeout(function () {
                            emoji.removeFromParent(true);
                        }, 10)
                    });
                } else {
                    emoji = playSpine(spFile, name + 1, false, function () {
                        setTimeout(function () {
                            emoji.removeFromParent(true);
                        }, 10)
                        playEffect('v' + name);
                        var emoji2 = playSpine(spFile, name + 2, false, function () {
                            setTimeout(function () {
                                emoji2.removeFromParent(true);
                            }, 10)
                        });
                        emojiNode.addChild(emoji2);
                    });
                }
                if ((name == "laotou" || name == "tuxue") && emoji) {
                    var psX = emojiNode.convertToWorldSpace(emojiNode.getPosition());
                    if (psX.x > cc.winSize.width / 2) {
                        emoji.setScaleX(-1);
                    }
                }
                emojiNode.addChild(emoji);
            } else {
                var resPath = chat.res[content];
                if (resPath) {
                    playAnimScene(emojiNode, resPath, 0, 0, true);
                } else {
                    var emoji = new cc.Sprite();
                    setSpriteFrameByName(emoji, content, chat.res.emoji_plist);
                    emojiNode.addChild(emoji);
                }
            }
            innerNodes.push(emojiNode);
        } else if (type == EmojiUtil.emojiType.emoji_sp) {
            duration = 5;
            var emojiNode = ChatInfo.getChildByName("emoji");
            emojiNode.setVisible(true);
            emojiNode.removeAllChildren();
            var emojiCfg = self._effectEmojiCfg[content];
            if (emojiCfg == undefined) {
                showToast('此版本不支持当前表情,请升级版本');
                return;
            }
            if (content == "11") {
                emojiCfg.name = 'caishen';
            }
            if (content == "12") {
                emojiCfg.name = 'qifu';
            }
            var eName = chat.res["sp_" + emojiCfg.name + '_json'];
            if (eName == undefined) {
                showToast('此版本不支持当前表情,请升级版本');
                return;
            }
            var emoji = playSpine(eName, emojiCfg.name + 1, false, function () {
                setTimeout(function () {
                    emoji.removeFromParent(true);
                }, 10)
                playEffect('v' + emojiCfg.name);
                var emoji2 = playSpine(eName, emojiCfg.name + 2, false, function () {
                    setTimeout(function () {
                        emoji2.removeFromParent(true);
                    }, 10)
                });
                emojiNode.addChild(emoji2);
            });
            emojiNode.addChild(emoji);
            innerNodes.push(emojiNode);
        } else if (type == EmojiUtil.emojiType.kwx_majiang) {//卡五星表情
            duration = 2.2;
            var emojiNode = ChatInfo.getChildByName("emoji");
            emojiNode.setVisible(true);
            emojiNode.removeAllChildren();
            var tab = [
                chat.res.sp_biaoqing_cuicu_json,
                chat.res.sp_biaoqing_zhuanqian_json,
                chat.res.sp_biaoqing_kaixin_json,
                chat.res.sp_biaoqing_kuqi_json,
                chat.res.sp_biaoqing_shengqi_json,
                chat.res.sp_biaoqing_BYEBYE_json,
                chat.res.sp_biaoqing_tuxue_json
            ];
            var animationNameTab = [
                "biaoqing_cuicu",
                "biaoqing_zhuanqian",
                "biaoqing_kaixin",
                "biaoqing_kuqi",
                "biaoqing_shengqi",
                "biaoqing_BYEBYE",
                "biaoqing_tuxue"
            ];
            var emoji = playSpine(tab[content - 1], animationNameTab[content - 1], false);
            emoji.setScale(0.5);
            if (row == 0) {
                emoji.setPosition(cc.p(-70, -80));
            }
            else if (row == 1) {
                emoji.setPosition(cc.p(-80, -100));
            }
            else if (row == 3) {
                emoji.setPosition(cc.p(-70, -100));
            }
            else {
                emoji.setPosition(cc.p(-70, -100));
            }
            emojiNode.addChild(emoji);
            innerNodes.push(emojiNode);
        } else if (type == EmojiUtil.emojiType.fsp) {
            var emojiNode = ChatInfo.getChildByName("emoji");
            emojiNode.setVisible(true);
            emojiNode.removeAllChildren();
            var resPath = chat.res[content];
            playAnimScene(emojiNode, resPath, 0, 0, true);
            innerNodes.push(emojiNode);
        } else if (type == EmojiUtil.emojiType.psz || type == EmojiUtil.emojiType.pdk || type == EmojiUtil.emojiType.niuniu) {
            var emojiNode = ChatInfo.getChildByName("emoji");
            emojiNode.setVisible(true);
            emojiNode.removeAllChildren();
            playAnimScene(emojiNode, chat.res['expression' + content], 0, 0, true);
            innerNodes.push(emojiNode);
        } else if (type == EmojiUtil.emojiType.emoji) {
            // content = 1;
            var contenttmp = 1;
            if (content && content.length > 0) {
                contenttmp = content.substr(10, 1);
            }
            var emojiNode = ChatInfo.getChildByName("emoji");
            emojiNode.setVisible(true);
            emojiNode.removeAllChildren();
            playAnimScene(emojiNode, chat.res['expression' + contenttmp], 0, 0, true);
            innerNodes.push(emojiNode);
        } else if (type == EmojiUtil.emojiType.phz) {
            var face = this.room.showChat(row, type, content, voice);
            innerNodes.push(face);
        } else if (type == EmojiUtil.emojiType.phz_hyphz) {
            var emojiNode = ChatInfo.getChildByName("emoji");
            emojiNode.setVisible(true);
            emojiNode.removeAllChildren();
            playAnimScene(emojiNode, chat.res['expression' + content], 0, 0, true);
            innerNodes.push(emojiNode);
        }
        else if (type == "oldemoji") {
            var emojiNode = ChatInfo.getChildByName("emoji");
            emojiNode.setVisible(true);
            emojiNode.removeAllChildren();
            var indexs = {1: 1, 2: 2, 3: 3, 4: 10, 5: 11};
            playAnimScene(emojiNode, chat.res['expression' + indexs[content]], 0, 0, true);
            innerNodes.push(emojiNode);
        } else if (type == 'text' || type == 'user_leave' || type == 'user_back') {
            var spriteBg = ChatInfo.getChildByName("qp");
            spriteBg.setVisible(true);
            var text = spriteBg.getChildByName("text");
            var tmptext = new ccui.Text();
            //tmptext.setFontRes(text.getFontName());
            tmptext.setFontSize(text.getFontSize());
            tmptext.setTextColor(cc.color(0, 0, 0));
            tmptext.enableOutline(cc.color(255, 255, 255), 1);
            tmptext.setString(content);
            var data = ChatInfo.getUserData();
            if (!data) {
                data = {
                    initWidth: spriteBg.getContentSize().width,
                    initpos: text.getPositionX(),
                }
                ChatInfo.setUserData(data);
            }
            var textSize = cc.size(tmptext.getContentSize().width, text.getContentSize().height);
            var size = cc.size(textSize.width + (data.initpos - data.initWidth / 2 != 0 ? 60 : 50), spriteBg.getContentSize().height);
            spriteBg.setContentSize(size);
            text.setContentSize(textSize);
            text.setString(content);
            text.setPositionX(size.width / 2 + (data.initpos - data.initWidth / 2));
            innerNodes.push(spriteBg);

            //如果是字牌玩法的话 需要处理离线及时显示
            if (gameData.subModule == "huzi") {
                if (type == 'user_leave' && this.room.setDisconnect) {
                    //用户切home
                    this.room.setDisconnect(uid, true);
                } else if (type == 'user_back' && this.room.setDisconnect) {
                    this.room.setDisconnect(uid, false);
                }
            }
        }

        ChatInfo.stopAllActions();
        ChatInfo.setVisible(true);
        ChatInfo.setOpacity(255);

        ChatInfo.runAction(cc.sequence(cc.delayTime(duration), cc.fadeOut(0.5), cc.callFunc(function () {
            for (var i = 0; i < innerNodes.length; i++)
                innerNodes[i].setVisible(false);
        })));

        for (var i = 0; i < innerNodes.length; i++) {
            var innerNode = innerNodes[i];
            innerNode.stopAllActions();
            innerNode.setVisible(true);
            innerNode.setOpacity(255);
            innerNode.runAction(cc.sequence(cc.delayTime(duration), cc.fadeOut(0.5)));
        }
        // console.log('showCat6......' + voice);
        if (voice && !window.inReview) {
            // if (app.appName == APP_NAME.LDFPF && gameData.subModule == "huzi") {
            //     var sex = 1;
            //     if(mRoom.erren && row == 1 ){
            //         row = 2;
            //     }
            //     if (row == 3)
            //         sex = mRoom.getUserByUserId(mRoom.sxUserId).sex;
            //     else
            //         sex = mRoom.getUserByUserPos(gameLayer['pos' + row]).sex;
            //     playEffect(voice, sex);
            // } else if (app.appName == APP_NAME.HYPHZ && gameData.subModule == "huzi") {
            //     var sex = mRoom.getUserByUserPos(gameLayer['pos' + row]).sex;
            //     playEffect(voice, sex);
            //
            // }
            // else {
            //     console.log('showCat7......' + voice);
            //     playEffect(voice);
            // }
            playEffect(voice);
        }
    },

};